function removeK(arr, k) {
    let stack = []
    for (let i = 0; i < arr.length; i++) {
        while (k && stack.length && arr[i] < stack[stack.length - 1]) {
            stack.pop();
            k--
        }
        stack.push(arr[i])
    }
    while (stack[0] == 0) {
        stack.shift();
    }
    let res = stack.join("")
    return res;
}

console.log(removeK([1, 2, 3, 4], 2))